import axios from 'axios'
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'
const instance  = axios.create({
    baseURL:'http://www.1024.com',
    timeout:5000
})

instance.interceptors.request.use((config)=>{
    // 开启进度条
    NProgress.start()
    return config
})
instance.interceptors.response.use(
    (response)=>{
        // 关闭进度条
        NProgress.done()
        // 判断状态码 返回对应的数据
        switch(response.data.code){
            case 200:
                return response.data.data;
            case 201:
                alert(response.data.message);
                return
        }
        
    },
    (error)=>{
        console.log(error.message);
        return new Promise()
    }

)

export default instance